/**
 * 
 */
package org.seginfo.httpfuzzer.header.impl;

import org.seginfo.httpfuzzer.header.AttackStrategy;
import org.seginfo.httpfuzzer.header.HeaderPropertyImpl;

/**
 * @author Administrador
 *
 */
public class ContentMD5 extends HeaderPropertyImpl {
	
	private static final String NAME = "Content-MD5";
	private static final String VALID = "e07186fbff6107d0274af02b8b930b65";
	//private static final String WILDCARD = "*/*";
	private static final int BAD_STRING_MIN_LENGTH = 32;
	private static final int BAD_STRING_LENGTH = 400;

	private static final int BAD_HEX_MIN_LENGTH = 16;
	private static final int BAD_HEX_LENGTH = 1024;

	/**
	 * @param attackStrategy
	 */
	public ContentMD5(AttackStrategy attackStrategy) {
		super(attackStrategy);
		this.value = this.generateValue();
	}

	/**
	 * @see org.seginfo.httpfuzzer.header.HeaderPropertyImpl#getName()
	 */
	public String getName() {
		return NAME;
	}

	/**
	 * @return
	 */
	private String generateValue() {
		
		String rv;

		double p = Math.random();
		if (p < 0.1) {
			rv = VALID;
		} else if (p < 0.2) {
			rv = "Z07186fbff6107d0274af02b8b930b65";
		} else if (p < 0.6) {
			rv = attackStrategy.getHexAttack(BAD_HEX_MIN_LENGTH, BAD_HEX_LENGTH);
		} else 
		{ 
			rv = attackStrategy.getStringAttack(BAD_STRING_MIN_LENGTH, BAD_STRING_LENGTH);
		}

		return rv;
	}
}
